package com.lizemin.entity;

import cn.hutool.json.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

/**
 * @author lzm
 * @date 2025/4/6 11:32
 * @description
 */
@Slf4j
@Data
@AllArgsConstructor
public class User implements HttpSessionBindingListener {

    private String username;

    private String password;

    private String role;

    private String sessionId;

    @Override
    public void valueBound(HttpSessionBindingEvent event) {
        String name = event.getName();
        User user = (User) event.getValue();
        log.info("name={}, value={}", name, JSONUtil.toJsonStr(user));
        log.info("用户名为【{}】的用户登录成功，角色为：【{}】", user.getUsername(), user.getRole());
    }

    @Override
    public void valueUnbound(HttpSessionBindingEvent event) {
        User user = (User) event.getValue();
        log.info("用户【{}】已退出登录，角色为：【{}】", user.getUsername(), user.getRole());
    }


}
